package com.neuedu.service.registration.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neuedu.bean.EmployeeSub;
import com.neuedu.mapper.EmployeeMapper;
import com.neuedu.service.registration.EmployeeService;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
	private EmployeeMapper em;
	@Override
	public List<EmployeeSub> getRegistDoctorList(String deptmentId, String registLevelId) {
		// TODO Auto-generated method stub
//		从数据库里按科室和挂号级别取出的医生信息
//		list中每一个map都是一个医生对象
//		List<EmployeeSub> elist=em.getRegistDoctorList(deptmentId, registLevelId);
		Map<String,Object> con=new HashMap<>();
		con.put("deptmentId", deptmentId);
		con.put("registLevelId", registLevelId);
		List<EmployeeSub> elist=em.getRegistDoctorList(con);
//		准备向前端发送的当日有出诊的医生列表
		List<EmployeeSub> curlist=new ArrayList<>();
//		取得当前日期
		Calendar c=Calendar.getInstance();
//		获得当前日期所属的下标
		int index=c.get(Calendar.DAY_OF_WEEK);
		System.out.println("index="+index);
//		获得当前日期上下午标志
		int flag=c.get(Calendar.AM_PM);
		System.out.println("flag="+flag);
		for (EmployeeSub emp : elist) {
//			取得医生排班规则完整字符串
			String s=emp.getScheduling().getWeekRule();
//			取出与当前星期值对应上午和下午字符串
			String sub=s.substring((index-1)*2,(index-1)*2+2);
			System.out.println("sub="+sub);
//			出诊情况
			char result=sub.charAt(flag);
//			符合条件的人会被添加到curlist
			if (result=='1') {
				curlist.add(emp);
			}
		}
		return curlist;
	}

}
